# A Model of the Fed's View on Inflation

This directory contains the source code for replicating the results in the paper:

Hasenzagl, T., Pellegrino, F., Reichlin, L., & Ricco, G. (2020). A Model of the Fed's View on Inflation.

An up-to-date version of the code (protected under a BSD 3-clause license) is also available on Github: https://github.com/fipelle/replication-hasenzagl-et-al-2020

The code is written in Julia 1.0.5 (https://julialang.org/) and uses a number of Julia packages. All necessary packages can be installed using the `import_packages.jl` script. To do so, start Julia and use the following command at the Julia REPL prompt:

`julia> include("import_packages.jl")`

## Running the code

The main file is `user_main.jl`. Within the script you can select the `run_type` and the `model_type`:  

* `run_type`:
	+  Setting `run_type=1` selects the in-sample estimation exercise. 
	+  Setting `run_type=2` selects the conditional forecasting exercise. This exercise also requires you to specify the start date for the forecasting exercise and the conditioning variables and time periods. Note that the paper does not include a conditional forecasting exercise.
	+ Setting `run_type=3` selects the out-of-sample forecasting exercise. This exercise also requires you to specify the start date of the forecasting exercise.

* `model_type`:
	+  Setting `model_type=1` selects the 8-variable model (the main model in the paper). 
	+  Setting `model_type=2` selects the model with global variables.  

After choosing `run_type` and `model_type`, run the script by starting Julia and using the following command at the Julia REPL prompt:

`julia> include("user_main.jl")`

## Data 
The data files are:

* *inflation.xlsx*: Contains the time series data used to estimate the main model and to obtain the main results: Real GDO, Employment, Unemployment Rate, CPI, Core CPI, University of Michigan Expected Inflation Rate, SPF Expected Inflation Rate. 
* *inflation_global.xlsx*: Contains the same data as *inflation.xlsx* and two additional series: Global Industrial Production (see Baumeister and Hamilton (2019)) and the Baltic Dry Index (BDI). The BDI is available here: https://www.balticexchange.com/en/index.html. 
* *gap.csv*: Contains measures of the output gap by the CBO and Greenbooks of the Federal Reserve. These measures are compared to the output gap estimated with the trend-cycle model. 
* *potential.csv*: Contains measures of potential output and NAIRU by the CBO. These measures are compared to the GDP and unemplyment trends estimated with the trend-cycle model.
* *INFCPI10YR.csv*: Contains a measure of 10 year expectations for CPI inflation from the Survey of Professional Forecasters. This measure is compared to the inflation trend estimated with the trend-cycle model.

## Code
The Julia files are:

* *MetropolisWithinGibbs.jl*: Defines a Julia module that contains the functions and structures used to estimate the state-space model with a Metropolis-Within-Gibbs algorithm.
* *tc_main.jl*: Standardizes the data, executes the estimation exercise (either in-sample, out-of-sample, or conditional forecast), and saves the results. 
* *tc_mwg.jl*: Sets the structure of the state space for the main 8-variable model.
* *tc_mwg_global.jl*: Sets the structure of the state space for the global model.
* *mwg_main.jl*, *mwg_run.jl*: Estimates the state-space model using the Metropolis-Within-Gibbs algorithm.
* *kalman_diffuse!.jl*: Contains routines for a diffuse Kalman filter, smoother, and simulation smoother using the univariate approach for multivariate models.
* *read_data.jl*: Imports the data from *inflation.xlsx* (or *inflation_global.xlsx*).
* *quarterly2monthly.jl*: Introduces missing values into a quarterly series to match the size of a monthly series.
* *set_par.jl*: Updates the state-space parameters. 
* *ex_blkdiag.jl*, *ex_inv.jl*, *ex_ismember.jl*: Functions that customize a number of standard operations, such as matrix inversion or block diagonalization of matrices.
* *get_logjacobian.jl*, *get_mwg_jump.jl*, *get_par_bound.jl*, *get_par_unb.jl*, *get_progress.jl*, *get_random_disturbance.jl*: Auxiliary functions used in the estimation.

## Figures and Tables

The figures and tables are created in two Jupyter (https://jupyter.org/) notebooks:

* `iis_charts.ipynb`: creates all figures relating to the in-sample estimation of the main 8-variable model.
* `iis_charts_global.ipynb`: creates all figures relating to the in-sample estimation of the global model.
* `oos_charts.ipynb`: creates all figures relating to the out-of-sample forecasting exercise and the RMSE of the trend-cycle model relative to the RMSE of a random walk with drift.


